package behaviourdrivendevelopmentexample.steps;

import behaviourdrivendevelopmentexample.classes.Vehicle;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

public class BreakingSimulationSteps {

    private Vehicle vehicle;
    private int speed;

    @Given("A vehicle travelling at $speed km/h")
    public void givenAVehicleAtASpeed(int speed) {
        vehicle = new Vehicle(speed);
        this.speed = speed;
    }

    @When("The brakes are applied")
    public void applyTheBreaks() {
        vehicle.applyBreaks();
    }

    @Then("The vehicle must have slowed down")
    public void theVehicleShouldBeSlower() {
        if(vehicle.getSpeed() > speed) {
            throw(new AssertionError("Vehicle did not slow down"));
        }
    }
}
